<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page pageEncoding="UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<h1>System Config</h1>

<script type="text/javascript">
    function check_submit() {
        clean();
        var index = 0;
        $('input[name$="ratePlans"]').each(function () {
            if ($(this).attr("checked")) {
                var inputStr = "<input type=\"hidden\" name=ratePlanCodes[" + index + "] value=\"" + $(this).val() + "\" />";
                $("#list_hotel_form").append(inputStr);
                index++;
            }
        });

        document.forms[0].submit();
    }
    function clean() {
        $('input[name$="ratePlans"]').each(function () {
            $(this).remove($(this));
        });
    }
</script>

<div class="main">
    <div class="box_side search_hotel clearfix">
        <form action="update.dhtml" id="list_hotel_form" method="post">
            <input type="button" value="Back" class="common_button" onclick="javascript:history.go(-1);">
            <fieldset>
                <legend>
                    <span class="title">Channel</span>
                </legend>
                <table class="table_list">
                    <tr>
                        <td class="key">Channel Code:</td>
                        <td class="value">
                            <input type="hidden" name="channel.id" value="${channel.id}"/>
                            <input type="text" value="${channel.derbyChannelCode}"
                                   minlength="1" maxlength="40" size="20"
                                   name="channel.derbyChannelCode" readonly="readonly"/></td>
                    </tr>
                    <tr>
                        <td class="key">User Name:</td>
                        <td class="value"><input type="text" id="rate_plan_name" class="required"
                                                 name="channel.userName" size="20"
                                                 minlength="1" maxlength="40" value="${channel.userName}"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="key">Password:</td>
                        <td class="value"><input name="channel.password" class="required" value="${channel.password}"
                                                 minlength="1" maxlength="40">
                        </td>
                    </tr>
                    <tr>
                        <td class="key">IATA NO.:</td>
                        <td class="value"><input name="channel.iataNumber" class="required"
                                                 value="${channel.iataNumber}"
                                                 minlength="1" maxlength="40">
                        </td>
                    </tr>
                    <tr>
                        <td class="key">Rate Plan:</td>
                        <td class="value">
                            <s:iterator value="ratePlanList" var="ratePlan" status="row">
                                &nbsp;${ratePlan.code}:<input type="checkbox"
                                name="ratePlans" value="${ratePlan.code}"
                                <s:iterator value="channel.ratePlans" var="channelRatePlan">
                                    <s:if test="#channelRatePlan.code ==#ratePlan.code">
                                        checked="checked"
                                    </s:if>
                                </s:iterator>
                                />&nbsp;&nbsp;&nbsp;&nbsp;
                            </s:iterator>
                        </td>
                    </tr>
                </table>
            </fieldset>
            <input type="button" value="Save" class="common_button" onclick="check_submit();"/>
        </form>
    </div>
</div>